/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package continuity.View;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

/**
 *
 * @author FornetTeam
 */
public class RoomView {
    private final NodeView[][] nodeViews;
    
    /**
     * A RoomView konstruktora.
     * @param nodeViews A szoba NodeView-jainak listája. Ha null, akkor üresszoba.
     */
    public RoomView(NodeView[][] nodeViews){
        this.nodeViews = nodeViews;
    }
    
    /**
     * A karakter pozíciójának lekérdezése.
     * @param characterNumber A karakter sorszáma.
     * @return A karakter pozíciója.
     */
    public int[] getCharacterPosition(int characterNumber) {
        if(nodeViews[0][0]!=null) {
            for (int j = 0; j < nodeViews.length; j++) {
                for (int k = 0; k < nodeViews[j].length; k++) {
                    if (nodeViews[j][k].IsHere(characterNumber)){
                        return new int[] {
                            k*ViewParameters.ElementWidth,
                            j*ViewParameters.ElementHeight};
                    }
                }
            }
        }
        return new int[]{-1, -1};
    }

    /**
     * Visszaadja a RoomView méretét.
     * @return A RoomView mérete.
     */
    public Dimension getDimension() {
        Dimension dimension = new Dimension(
                nodeViews[0].length * ViewParameters.ElementWidth,
                nodeViews.length * ViewParameters.ElementHeight);
        return dimension;
    }

    /**
     * A szoba kirajzolása.
     * @param g Ide rajzolódik ki.
     */
    public void paintView(Graphics g) {
        if (nodeViews[0][0] != null){
            for (int i = 0; i < nodeViews.length; i++) {
                for (int j = 0; j < nodeViews[i].length; j++) {
                    Graphics nodeG = g.create(
                            j*ViewParameters.ElementWidth,
                            i*ViewParameters.ElementHeight,
                            ViewParameters.ElementWidth,
                            ViewParameters.ElementHeight);
                    nodeViews[i][j].paintView(nodeG);
                }
            }
        }
        Color oldColor=g.getColor();
        g.setColor(ViewParameters.roomBorderColor);
        g.drawRect(0, 0, 
                nodeViews[0].length*ViewParameters.ElementWidth-1, 
                nodeViews.length*ViewParameters.ElementHeight-1);
        g.setColor(oldColor);
    }
    
}
